home *** CD-ROM | disk | FTP | other *** search
- // main.c
-
- ProcInfoType __procinfo = kThinkCStackBased; // this must match the ProcInfoType
- // used to call this resource in the
- // calling app
-
- #include <A4Stuff.h>
- #include <CodeFragments.h>
-
- #include "main.h"
- #include "filter.h"
- #include "AppPrefs.h"
-
- SpotlightGlobals glob;
-
- /*
- Various helpful comments.
-
- <KeithS> Drop into Macsbug, and type dh 7003 a829
- <KeithS> Oh. It's telling you that, in order to call this trap, it's a dispatched trap
- with the dispatch selector in register d0. There's a macro which lets you specify the
- selector word, as I recall.
- <DaveK> keith: 3 is the selector word?
- <KeithS> Yes.
-
- <KeithS> It's at 0x174. Four longs. [the global keymap]
-
- <whyte> davek, patch SetTrapAddress...then right before the finder launches the process
- manager will patch WaitNextEvent, you get to insert your patch there
-
- <SoMeOnE> DaveK: you would call ADBOP, with listen, Register 0 [to get keyboard info]
- */
-
- pascal OSErr MyGestaltSelector(OSType selector, long *response);
-
- enum {
- uppMainProcInfo = kThinkCStackBased
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(SpotlightGlobals*)))
- };
-
- typedef void (*MainProcPtr)(SpotlightGlobals *glob);
-
- #if powerc
- typedef UniversalProcPtr MainProcUPP;
-
- #define CallMainProc(userRoutine, glob) \
- CallUniversalProc((UniversalProcPtr)(userRoutine), uppMainProcInfo, glob)
- #else
- typedef MainProcPtr MainProcUPP;
-
- #define CallMainProc(userRoutine, glob) \
- (*(userRoutine))(glob)
- #endif
-
- void main(void) {
- long saveA4;
- Handle rsrc;
- MainProcUPP mainProc;
- SelectorFunctionUPP mySelector;
-
- EnterCodeResource();
-
- rsrc = Get1Resource('INIT',0);
- DetachResource(rsrc);
- HLock(rsrc);
-
- // this is so the regions etc. we allocate will not be destroyed after our extension loads
- SetZone(SystemZone());
-
- // initialization
-
- PrefsLoad(&glob.prefs);
- glob.active = glob.activating = glob.deactivating = false;
-
- glob.showSpotlightUPP = NewRoutineDescriptor((ProcPtr)ShowSpotlight, uppShowSpotlightInfo, GetCurrentArchitecture());
- glob.makeSpotlightUPP = NewRoutineDescriptor((ProcPtr)MakeSpotlightRgn, uppMakeSpotlightInfo, GetCurrentArchitecture());
-
- glob.spotlightRgn = NewRgn();
- glob.oldlightRgn = NewRgn();
- glob.newlightRgn = NewRgn();
- glob.scratchRgn = NewRgn();
-
- MakeSpotlightRgn();
-
- // 68k patches
-
- rsrc = Get1Resource('Patc', 128);
- DetachResource(rsrc);
- HLock(rsrc);
- mainProc = (MainProcUPP)*rsrc;
- CallMainProc(mainProc, &glob);
-
- // gestalt selector to interface with app
-
- mySelector = NewSelectorFunctionProc(MyGestaltSelector);
- NewGestalt('liTE', mySelector);
-
- saveA4 = SetA4(0);
- SetA4(saveA4);
- InstallEventFilter((FilterHelperUPP) EventFilterHelper, (Ptr) saveA4);
-
- ExitCodeResource();
- }
-
- pascal OSErr MyGestaltSelector(OSType selector, long *response) {
- EnterCodeResource();
- *response = (long)&glob;
- ExitCodeResource();
- return noErr;
- }
-
- void MoveSpotlightOffscreen(void) {
- Rect screenBounds = (*LMGetGrayRgn())->rgnBBox;
- if (screenBounds.top > 0) screenBounds.top = 0; // for menubar
-
- OffsetRgn(glob.spotlightRgn,
- (screenBounds.left - glob.lightCenter.h) - glob.prefs.spotlightSize/2,
- (screenBounds.top - glob.lightCenter.v) - glob.prefs.spotlightSize/2);
- glob.lightCenter.h = screenBounds.left - glob.prefs.spotlightSize/2;
- glob.lightCenter.v = screenBounds.top - glob.prefs.spotlightSize/2;
- }
-
- void MakeSpotlightRgn(void) {
- GrafPtr oldPort, wmgrPort;
- Rect screenBounds, circleRect;
-
- GetPort(&oldPort);
- GetCWMgrPort((CGrafPtr*)&wmgrPort);
- SetPort(wmgrPort);
-
- OpenRgn();
-
- screenBounds = (*LMGetGrayRgn())->rgnBBox;
- if (screenBounds.top > 0) screenBounds.top = 0; // for menubar
- circleRect.top = screenBounds.top;
- circleRect.bottom = screenBounds.top + glob.prefs.spotlightSize;
- circleRect.left = screenBounds.left;
- circleRect.right = screenBounds.left + glob.prefs.spotlightSize;
-
- FrameOval(&circleRect);
- CloseRgn(glob.spotlightRgn);
-
- glob.lightCenter.h = glob.lightCenter.v = glob.prefs.spotlightSize/2;
- MoveSpotlightOffscreen();
-
- SetPort(oldPort);
- }